﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HA.ModFlow.Domain.DomainLayer;

namespace HA.ModFlow.Controls.Windows
{
    /// <summary>
    /// winPackages.xaml 的交互逻辑
    /// </summary>
    public partial class winPackages : Window
    {
        public winPackages(ModelOption option,ModFlowData modflow)
        {
            InitializeComponent();
            this._modelOption = option;
            this._ss = modflow.SourceSinks;

            this._modflow = modflow;

            this._wellEnable = _ss.Wells.Enabled;
            this._rechargeEnable = _ss.Recharges.Enabled;
            this._drainEnable = _ss.Drains.Enabled;
            this._riverEnable = _ss.Rivers.Enabled;
            this._genHeadEnable = _ss.GeneralHeads.Enabled;
            this._specHeadEnable = _ss.SpecifiedHeads.Enabled;
            this._barrierEnable = _modflow.HfbData.Enabled;
            this._EVTEnable = _ss.Evts.Enabled;
            this._UZFEnable = _ss.UzfCollection.Enabled;

            Binding bindWell = new Binding();
            bindWell.Source = this;
            bindWell.Path = new PropertyPath("WellEnable");
            
            this.cbWell.SetBinding(CheckBox.IsCheckedProperty, bindWell);

            Binding bindRecharge = new Binding();
            bindRecharge.Source = this;
            bindRecharge.Path = new PropertyPath("RechargeEnable");
            this.cbRecharge.SetBinding(CheckBox.IsCheckedProperty, bindRecharge);

            Binding bindDrain = new Binding();
            bindDrain.Source = this;
            bindDrain.Path = new PropertyPath("DrainEnable");
            this.cbDrain.SetBinding(CheckBox.IsCheckedProperty, bindDrain);

            Binding bindRiver = new Binding();
            bindRiver.Source = this;
            bindRiver.Path = new PropertyPath("RiverEnable");
            this.cbRiver.SetBinding(CheckBox.IsCheckedProperty, bindRiver);


            Binding bindGenHead = new Binding();
            bindGenHead.Source = this;
            bindGenHead.Path = new PropertyPath("GenHeadEnable");
            this.cbGenHead.SetBinding(CheckBox.IsCheckedProperty, bindGenHead);

            Binding bindSpecHead = new Binding();
            bindSpecHead.Source = this;
            bindSpecHead.Path = new PropertyPath("SpecHeadEnable");
            this.cbSpecHead.SetBinding(CheckBox.IsCheckedProperty, bindSpecHead);

            Binding bindEVT = new Binding();
            bindEVT.Source = this;
            bindEVT.Path = new PropertyPath("EVTEnable");
            this.cbEvt.SetBinding(CheckBox.IsCheckedProperty,bindEVT);



            Binding bindBarrier = new Binding();
            bindBarrier.Source = this;
            bindBarrier.Path = new PropertyPath("BarrierEnable");
            this.cbBarrier.SetBinding(CheckBox.IsCheckedProperty, bindBarrier);

            Binding bindUzf = new Binding();
            bindUzf.Source = this;
            bindUzf.Path = new PropertyPath("UZFEnable");
            this.chkUzf.SetBinding(CheckBox.IsCheckedProperty, bindUzf);

            switch(_modelOption.InnerPack)
            {
                case INNERPACK.LPF:this.rbnLPF.IsChecked=true;
                     break;
                case INNERPACK.BCF:this.rbnBCF.IsChecked=true;
                     break;
            }

            switch (_modelOption.SolverPack)
            {
                case SOLVERPACK.SIP: this.rbnSIP.IsChecked = true;
                    break;
                case SOLVERPACK.PCG: this.rbnPCG.IsChecked = true;
                    break;
                case SOLVERPACK.DE4: this.rbnDE4.IsChecked = true;
                    break;
            }
        }

        bool _wellEnable;

        public bool WellEnable
        {
            get { return _wellEnable; }
            set { _wellEnable = value; }
        }

        bool _rechargeEnable;

        public bool RechargeEnable
        {
            get { return _rechargeEnable; }
            set { _rechargeEnable = value; }
        }

        bool _drainEnable;

        public bool DrainEnable
        {
            get { return _drainEnable; }
            set { _drainEnable = value; }
        }

        bool _riverEnable;

        public bool RiverEnable
        {
            get { return _riverEnable; }
            set { _riverEnable = value; }
        }
        bool _genHeadEnable;

        public bool GenHeadEnable
        {
            get { return _genHeadEnable; }
            set { _genHeadEnable = value; }
        }

        bool _specHeadEnable;

        public bool SpecHeadEnable
        {
            get { return _specHeadEnable; }
            set { _specHeadEnable = value; }
        }

        bool _EVTEnable;

        public bool EVTEnable
        {
            get { return _EVTEnable; }
            set { _EVTEnable = value; }
        }

        bool _barrierEnable;

        public bool BarrierEnable
        {
            get { return _barrierEnable; }
            set { _barrierEnable = value; }
        }

        bool _UZFEnable;

        public bool UZFEnable
        {
            get { return _UZFEnable; }
            set { _UZFEnable = value; }
        }


        ModelOption _modelOption;

        SourceSink _ss;

        ModFlowData _modflow;

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            this._ss.Wells.Enabled = _wellEnable;
            this._ss.Recharges.Enabled = _rechargeEnable;
            this._ss.Rivers.Enabled = _riverEnable;
            this._ss.Drains.Enabled = _drainEnable;
            this._ss.Evts.Enabled = _EVTEnable;
            this._ss.GeneralHeads.Enabled = _genHeadEnable;
            this._ss.SpecifiedHeads.Enabled = _specHeadEnable;
            this._ss.UzfCollection.Enabled = _UZFEnable;
            this._modflow.HfbData.Enabled = _barrierEnable;

            if (this.rbnSIP.IsChecked == true)
            {
                this._modelOption.SolverPack = SOLVERPACK.SIP;
            }
            else if (this.rbnDE4.IsChecked == true)
            {

                this._modelOption.SolverPack = SOLVERPACK.DE4;
            }
            else
            {
                this._modelOption.SolverPack = SOLVERPACK.PCG;
            }

            if (this.rbnLPF.IsChecked == true)
            {
                this._modelOption.InnerPack = INNERPACK.LPF;
            }
            else
                this._modelOption.InnerPack = INNERPACK.BCF;

            this.DialogResult = true;
            this.Close();
        }


    }
}
